package org.bugjail.servlet.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.SimpleTestCase;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.dataaccess.objects.TestCaseDAO;
import org.bugjail.servlet.BasicServlet;

/**
 * Servlet implementation class for Servlet: EditSimpleTestCaseServlet
 *
 */
 public class EditSimpleTestCaseServlet extends BasicServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public EditSimpleTestCaseServlet() {
		super();
	}

	@Override
	protected void action(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int tcid = Integer.parseInt(request.getParameter("tcid"));
		TestCaseDAO dao = DAOFactory.getDAOFactory().getTestCaseDAO();
		
		SimpleTestCase tc = (SimpleTestCase)dao.retrieveById(tcid);
		
		tc.setName(request.getParameter("name"));
		tc.setObjective(request.getParameter("objective"));
		tc.setSeverity(Integer.parseInt(request.getParameter("severity")));
		dao.update(tc);
		response.sendRedirect("TestCaseServlet?suiteid="+tc.getSuite().getId());
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}   	
}